package com.example.wm.SanWar.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wm.SanWar.entity.AlliesandUser;
import com.example.wm.SanWar.entity.GameUser;
import com.example.wm.SanWar.entity.Pointsrecord;
import com.example.wm.SanWar.entity.RecordofWarMeritConversion;
import com.example.wm.SanWar.mapper.AlliesandUserMapper;
import com.example.wm.SanWar.mapper.GameUserMapper;
import com.example.wm.SanWar.mapper.PointsrecordMapper;
import com.example.wm.SanWar.mapper.RecordofWarMeritConversionMapper;
import com.example.wm.SanWar.service.RecordofWarMeritConversionService;
import com.example.wm.common.Result;
import com.example.wm.common.ResultData;
import com.example.wm.utils.TsyUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Slf4j
@RestController
@RequestMapping("/RecordofWarMeritConversion")
public class RecordofWarMeritConversionController {
    @Resource
    private TsyUtils tsyUtils;
    @Resource
    private RecordofWarMeritConversionMapper recordofWarMeritConversionMapper;
    @Resource
    private RecordofWarMeritConversionService recordofWarMeritConversionService;
    @Resource
    private AlliesandUserMapper alliesandUserMapper;
    @Resource
    private GameUserMapper gameUserMapper;
    @Resource
    private PointsrecordMapper pointsrecordMapper;
    @Transactional
    @PostMapping("/find")
    public Result find(@RequestBody RecordofWarMeritConversion recordofWarMeritConversion) {
        LambdaQueryWrapper<RecordofWarMeritConversion> lq=new LambdaQueryWrapper<>();
        lq.eq(RecordofWarMeritConversion::getCreatenameid,recordofWarMeritConversion.getCreatenameid());
        List<RecordofWarMeritConversion> list=recordofWarMeritConversionMapper.selectList(lq);
        if(list.isEmpty()){
            return ResultData.success("无数据");
        }else{
            for (RecordofWarMeritConversion r:list){
                LambdaQueryWrapper<AlliesandUser> lq2=new LambdaQueryWrapper<>();
                lq2.eq(AlliesandUser::getId,r.getCreatenameid());
                AlliesandUser one = alliesandUserMapper.selectOne(lq2);
                if(!Objects.equals(one.getName(), r.getCreatename())){
                    r.setCreatename(one.getName());
                    r.setCreateappoint(one.getAppoint());
                }

            }

            return ResultData.success(list);
        }

    }
    @Transactional
    @PostMapping("/insert")
    public Result insert(@RequestBody RecordofWarMeritConversion recordofWarMeritConversion) {


           recordofWarMeritConversion.setUpdatetime(tsyUtils.getnowtime());
           recordofWarMeritConversion.setCreatetime(tsyUtils.getnowtime());
           int b=    recordofWarMeritConversionMapper.insert(recordofWarMeritConversion);


        LambdaQueryWrapper<AlliesandUser> lq=new LambdaQueryWrapper<>();
        lq.eq(AlliesandUser::getCreatename,recordofWarMeritConversion.getCreatename());
        lq.eq(AlliesandUser::getStatus,"在盟");

        List<AlliesandUser> list=alliesandUserMapper.selectList(lq);
        if(!list.isEmpty()){
            for (AlliesandUser a:list) {
                Integer number2 = 0;
                Integer number3 = 0;
                int Difference = 0;
                LambdaQueryWrapper<GameUser> lqu = new LambdaQueryWrapper<>();
                lqu.eq(GameUser::getId, a.getUserid());
                GameUser gu = gameUserMapper.selectOne(lqu);
                System.out.println("GameUser" + gu.getSoil() + gu.getDismantletheenemy());
                float number = 0;
                try {
                    // 获取浮点数值
                    float battleAchievement = recordofWarMeritConversion.getBattleachievement();
                    float helpAchievement = recordofWarMeritConversion.getHelpachievement();
                    float soilPoint = recordofWarMeritConversion.getSoilpoint();
                    float dismantleTheEnemy = recordofWarMeritConversion.getDismantletheenemy();
                    float demolishthecity = recordofWarMeritConversion.getDemolishthecity();
                    float attackacity = recordofWarMeritConversion.getAttackacity();
                    float annihilatetheenemy = recordofWarMeritConversion.getAnnihilatetheenemy();

                    // 打印获取的浮点数值
                    System.out.println("battleAchievement: " + battleAchievement);
                    System.out.println("helpAchievement: " + helpAchievement);
                    System.out.println("soilPoint: " + soilPoint);
                    System.out.println("dismantleTheEnemy: " + dismantleTheEnemy);
                    System.out.println("demolishthecity: " + demolishthecity);
                    System.out.println("attackacity: " + attackacity);
                    System.out.println("annihilatetheenemy: " + annihilatetheenemy);

                    // 进行计算
                   String details = null;
                    if(battleAchievement!=0.0){
                        number += safeParseInt(gu.getMilitaryall(), a.getName()) / battleAchievement;
                        details=" 战功:"+battleAchievement;
                    }
                    if ( helpAchievement!=0.0) {
                        number += safeParseInt(gu.getHoldingall(), a.getName()) / helpAchievement;
                        details+=" 助攻:"+helpAchievement;
                    }
                    if (soilPoint!=0.0) {
                        number += safeParseInt(gu.getSoil(), a.getName()) / soilPoint;
                        details+=" 翻地:"+soilPoint;
                    }
                    if(dismantleTheEnemy!=0.0){
                        number += safeParseInt(gu.getDismantletheenemy(), a.getName()) / dismantleTheEnemy;
                        details+=" 拆敌:"+dismantleTheEnemy;
                    }
                    if(demolishthecity!=0.0){
                        number += safeParseInt(gu.getDemolishthecity(), a.getName()) / demolishthecity;
                        details+=" 拆城:"+demolishthecity;
                    }
                    if(attackacity!=0.0){
                        number += safeParseInt(gu.getAttackacity(), a.getName()) / attackacity;
                        details+=" 攻城:"+attackacity;
                    }
                    if(annihilatetheenemy!=0.0){
                        number += safeParseInt(gu.getAnnihilatetheenemy(), a.getName()) / annihilatetheenemy;
                        details+=" 攻城灭敌:"+annihilatetheenemy;
                    }
                    // 检查结果是否为 NaN
                    if (Float.isNaN(number)) {
                        number = 0.0f;
                    }
                    if(Objects.equals(a.getName(), "檀")){
                        // 打印计算结果
                        System.out.println("Number: " + number );
                    }



                    // 继续处理
                    int result = Math.round(number);
                    int TurnovervalueaLL;
                    if(a.getTurnovervalueaLL()!=null){
                        TurnovervalueaLL=Integer.parseInt(a.getTurnovervalueaLL());

                    }else{
                        TurnovervalueaLL=0;
                    }
                    number2 =TurnovervalueaLL  + result;
//                   System.out.println("result>Integer: " + result + " number2: " + number2 + " PointesAll: " + TurnovervalueaLL);
                    int pointAll;
                    if(a.getPointesAll()!=null){
                        pointAll= Integer.parseInt(a.getPointesAll());
                    }else{
                        pointAll=0;
                    }


                    if (number2 > pointAll) {
                    Difference = number2 - pointAll;
                        //新增积分记录
                    Pointsrecord pointsrecord = new Pointsrecord();
                    pointsrecord.setCreatetime(tsyUtils.getnowtime());
                    pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                    pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                    pointsrecord.setPoints(Difference);
                    pointsrecord.setFinnalpoints(number2);
                    pointsrecord.setStatuss("奖励");
                    pointsrecord.setRewordpoeple(a.getName());
                    pointsrecord.setType("周转积分比例调整");
                    pointsrecord.setType2("积分");
                    pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                    pointsrecord.setRewordpoepleid(a.getId());
                    pointsrecord.setCompetitionseason(a.getCompetitionseason());
                    pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,比例("+details+")");
                int bs=   pointsrecordMapper.insert(pointsrecord);
                System.out.println("pointsrecordMapper"+bs);
                    //更新积分
                    a.setPointesAll(String.valueOf(number2));
                    alliesandUserMapper.updateById(a);
                } else if(number2 < pointAll){

                    Difference =   pointAll-(TurnovervalueaLL+result);
                       //新增积分记录
                    Pointsrecord pointsrecord = new Pointsrecord();
                    pointsrecord.setCreatetime(tsyUtils.getnowtime());
                    pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                    pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                    pointsrecord.setPoints(Difference);
                    pointsrecord.setFinnalpoints(number2);
                    pointsrecord.setStatuss("扣减");
                    pointsrecord.setRewordpoeple(a.getName());
                    pointsrecord.setType("周转积分比例调整");
                    pointsrecord.setType2("积分");
                        pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                        pointsrecord.setRewordpoepleid(a.getId());
                        pointsrecord.setCompetitionseason(a.getCompetitionseason());

                    pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,比例("+details+")");
                    int bs=   pointsrecordMapper.insert(pointsrecord);
                    System.out.println("pointsrecordMapper"+bs);

                    //更新积分
                    a.setPointesAll(String.valueOf(number2));
                    alliesandUserMapper.updateById(a);
                }
                //可用积分
                    int Turnovervalue;
                    if(a.getTurnovervalue()!=null){
                        Turnovervalue=Integer.parseInt(a.getTurnovervalue());
                    }else{
                        Turnovervalue=0;
                    }

//                    System.out.println("result>Integer: " + result + " number2: " + number2 + " PointesAll: " + TurnovervalueaLL);
                    int points;
                    if(a.getPointes()!=null){
                        points= Integer.parseInt(a.getPointes());
                    }else{
                        points=0;
                    }

                    int militaryvalue;
                    if(a.getTurnovermilitaryvalue()!=null){
                        militaryvalue= Integer.parseInt(a.getTurnovermilitaryvalue());
                    }else{
                        militaryvalue=0;
                    }
                number2 = Turnovervalue + result;
                if (number2 > points) {
                    number3 = militaryvalue + result;
                    Difference = number2 - points;
                    //新增可用积分记录
                    Pointsrecord pointsrecord = new Pointsrecord();
                    pointsrecord.setCreatetime(tsyUtils.getnowtime());
                    pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                    pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                    pointsrecord.setPoints(Difference);
                    pointsrecord.setFinnalpoints(number2);
                    pointsrecord.setStatuss("奖励");
                    pointsrecord.setRewordpoeple(a.getName());
                    pointsrecord.setType("周转积分比例调整");
                    pointsrecord.setType2("可用积分");
                    pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                    pointsrecord.setRewordpoepleid(a.getId());
                    pointsrecord.setCompetitionseason(a.getCompetitionseason());

                    pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,比例("+details+")");
                    pointsrecordMapper.insert(pointsrecord);
                    //更新 可用积分 军工
                    a.setPointes(String.valueOf(number2));
                    a.setMilitaryIndustryall(String.valueOf(number3));
                    alliesandUserMapper.updateById(a);
                } else if(number2 < points){
                    Difference =   points-(Turnovervalue+result);
//                    turnovermilitaryvalue
                    number3 =  points-(militaryvalue + result);

                    //新增可用积分记录
                    Pointsrecord pointsrecord = new Pointsrecord();
                    pointsrecord.setCreatetime(tsyUtils.getnowtime());
                    pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                    pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                    pointsrecord.setPoints(Difference);
                    pointsrecord.setFinnalpoints(number2);
                    pointsrecord.setStatuss("扣减");
                    pointsrecord.setRewordpoeple(a.getName());
                    pointsrecord.setType("周转积分比例调整");
                    pointsrecord.setType2("可用积分");
                    pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                    pointsrecord.setRewordpoepleid(a.getId());
                    pointsrecord.setCompetitionseason(a.getCompetitionseason());

                    pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,比例("+details+")");
                    pointsrecordMapper.insert(pointsrecord);
//                    //更新 可用积分 军工
                    a.setPointes(String.valueOf(number2));
                    a.setMilitaryIndustryall(String.valueOf(number3));
                    alliesandUserMapper.updateById(a);
                }
                } catch (NumberFormatException e) {
                    // 处理转换异常
                    System.out.println("Invalid number format for one of the strings: " + e.getMessage());

                } catch (Exception e) {
                    // 处理其他可能的异常
                    System.out.println("Unexpected error occurred: " + e.getMessage());

                }
            }

        }
        return ResultData.success(b);
    }

    @Transactional
    @PostMapping("/update")
    public Result update(@RequestBody RecordofWarMeritConversion recordofWarMeritConversion) {


        recordofWarMeritConversion.setUpdatetime(tsyUtils.getnowtime());
//        recordofWarMeritConversion.setCreatetime(tsyUtils.getnowtime());
        int b=    recordofWarMeritConversionMapper.updateById(recordofWarMeritConversion);


        LambdaQueryWrapper<AlliesandUser> lq=new LambdaQueryWrapper<>();
        lq.eq(AlliesandUser::getCreatename,recordofWarMeritConversion.getCreatename());
        lq.eq(AlliesandUser::getStatus,"在盟");

        List<AlliesandUser> list=alliesandUserMapper.selectList(lq);
        if(!list.isEmpty()){
            for (AlliesandUser a:list) {
                Integer number2 = 0;
                Integer number3 = 0;
                int Difference = 0;
                LambdaQueryWrapper<GameUser> lqu = new LambdaQueryWrapper<>();
                lqu.eq(GameUser::getId, a.getUserid());
                GameUser gu = gameUserMapper.selectOne(lqu);
                System.out.println("GameUser" + gu.getSoil() + gu.getDismantletheenemy());
                float number = 0;
                String details="";
                try {
                    // 获取浮点数值
                    float battleAchievement = recordofWarMeritConversion.getBattleachievement();
                    float helpAchievement = recordofWarMeritConversion.getHelpachievement();
                    float soilPoint = recordofWarMeritConversion.getSoilpoint();
                    float dismantleTheEnemy = recordofWarMeritConversion.getDismantletheenemy();
                    float demolishthecity = recordofWarMeritConversion.getDemolishthecity();
                    float attackacity = recordofWarMeritConversion.getAttackacity();
                    float annihilatetheenemy = recordofWarMeritConversion.getAnnihilatetheenemy();

                    // 打印获取的浮点数值
                    System.out.println("battleAchievement: " + battleAchievement);
                    System.out.println("helpAchievement: " + helpAchievement);
                    System.out.println("soilPoint: " + soilPoint);
                    System.out.println("dismantleTheEnemy: " + dismantleTheEnemy);
                    System.out.println("demolishthecity: " + demolishthecity);
                    System.out.println("attackacity: " + attackacity);
                    System.out.println("annihilatetheenemy: " + annihilatetheenemy);

                    // 进行计算
                    if(battleAchievement!=0.0){
                        number += safeParseInt(gu.getMilitaryall(), a.getName()) / battleAchievement;
                        details=" 战功:"+battleAchievement;
                    }
                    if ( helpAchievement!=0.0) {
                        number += safeParseInt(gu.getHoldingall(), a.getName()) / helpAchievement;
                        details+=" 助攻:"+helpAchievement;
                    }
                    if (soilPoint!=0.0) {
                        number += safeParseInt(gu.getSoil(), a.getName()) / soilPoint;
                        details+=" 翻地:"+soilPoint;
                    }
                    if(dismantleTheEnemy!=0.0){
                        number += safeParseInt(gu.getDismantletheenemy(), a.getName()) / dismantleTheEnemy;
                        details+=" 拆敌:"+dismantleTheEnemy;
                    }
                    if(demolishthecity!=0.0){
                        number += safeParseInt(gu.getDemolishthecity(), a.getName()) / demolishthecity;
                        details+=" 拆城:"+demolishthecity;
                    }
                    if(attackacity!=0.0){
                        number += safeParseInt(gu.getAttackacity(), a.getName()) / attackacity;
                        details+=" 攻城:"+attackacity;
                    }
                    if(annihilatetheenemy!=0.0){
                        number += safeParseInt(gu.getAnnihilatetheenemy(), a.getName()) / annihilatetheenemy;
                        details+=" 攻城灭敌:"+annihilatetheenemy;
                    }

                    // 检查结果是否为 NaN
                    if (Float.isNaN(number)) {
                        number = 0.0f;
                    }
//                    if(Objects.equals(a.getName(), "檀")){
//                        // 打印计算结果
//                        System.out.println("Number: " + number );
//                    }



                    // 继续处理
                    int result = Math.round(number);
                    int TurnovervalueaLL;
                    if(a.getTurnovervalueaLL()!=null){
                        TurnovervalueaLL=Integer.parseInt(a.getTurnovervalueaLL());

                    }else{
                        TurnovervalueaLL=0;
                    }
                    number2 =TurnovervalueaLL  + result;
//                   System.out.println("result>Integer: " + result + " number2: " + number2 + " PointesAll: " + TurnovervalueaLL);
                    int pointAll;
                    if(a.getPointesAll()!=null){
                        pointAll= Integer.parseInt(a.getPointesAll());
                    }else{
                        pointAll=0;
                    }


                    if (number2 > pointAll) {
                        Difference = number2 - pointAll;
                        //新增积分记录
                        Pointsrecord pointsrecord = new Pointsrecord();
                        pointsrecord.setCreatetime(tsyUtils.getnowtime());
                        pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                        pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                        pointsrecord.setPoints(Difference);
                        pointsrecord.setFinnalpoints(number2);
                        pointsrecord.setStatuss("奖励");
                        pointsrecord.setRewordpoeple(a.getName());
                        pointsrecord.setType("周转积分比例调整");
                        pointsrecord.setType2("积分");
                        pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                        pointsrecord.setRewordpoepleid(a.getId());
                        pointsrecord.setCompetitionseason(a.getCompetitionseason());

                        pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,新比例("+details+")");
                        int bs=   pointsrecordMapper.insert(pointsrecord);
                        System.out.println("pointsrecordMapper"+bs);
                        //更新积分
                        a.setPointesAll(String.valueOf(number2));
                        alliesandUserMapper.updateById(a);
                    } else if(number2 < pointAll){

                        Difference =   pointAll-(TurnovervalueaLL+result);
                        //新增积分记录
                        Pointsrecord pointsrecord = new Pointsrecord();
                        pointsrecord.setCreatetime(tsyUtils.getnowtime());
                        pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                        pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                        pointsrecord.setPoints(Difference);
                        pointsrecord.setFinnalpoints(number2);
                        pointsrecord.setStatuss("扣减");
                        pointsrecord.setRewordpoeple(a.getName());
                        pointsrecord.setType("周转积分比例调整");
                        pointsrecord.setType2("积分");
                        pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                        pointsrecord.setRewordpoepleid(a.getId());
                        pointsrecord.setCompetitionseason(a.getCompetitionseason());

                        pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,新比例("+details+")");
                        int bs=   pointsrecordMapper.insert(pointsrecord);
                        System.out.println("pointsrecordMapper"+bs);

                        //更新积分
                        a.setPointesAll(String.valueOf(number2));
                        alliesandUserMapper.updateById(a);
                    }
                    //可用积分
                    int Turnovervalue;
                    if(a.getTurnovervalue()!=null){
                        Turnovervalue=Integer.parseInt(a.getTurnovervalue());
                    }else{
                        Turnovervalue=0;
                    }

//                    System.out.println("result>Integer: " + result + " number2: " + number2 + " PointesAll: " + TurnovervalueaLL);
                    int points;
                    if(a.getPointes()!=null){
                        points= Integer.parseInt(a.getPointes());
                    }else{
                        points=0;
                    }

                    int militaryvalue;
                    if(a.getTurnovermilitaryvalue()!=null){
                        militaryvalue= Integer.parseInt(a.getTurnovermilitaryvalue());
                    }else{
                        militaryvalue=0;
                    }
                    number2 = Turnovervalue + result;
                    if (number2 > points) {
                        number3 = militaryvalue + result;
                        Difference = number2 - points;
                        //新增可用积分记录
                        Pointsrecord pointsrecord = new Pointsrecord();
                        pointsrecord.setCreatetime(tsyUtils.getnowtime());
                        pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                        pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                        pointsrecord.setPoints(Difference);
                        pointsrecord.setFinnalpoints(number2);
                        pointsrecord.setStatuss("奖励");
                        pointsrecord.setRewordpoeple(a.getName());
                        pointsrecord.setType("周转积分比例调整");
                        pointsrecord.setType2("可用积分");
                        pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                        pointsrecord.setRewordpoepleid(a.getId());
                        pointsrecord.setCompetitionseason(a.getCompetitionseason());

                        pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,新比例("+details+")");
                        pointsrecordMapper.insert(pointsrecord);
                        //更新 可用积分 军工
                        a.setPointes(String.valueOf(number2));
                        a.setMilitaryIndustryall(String.valueOf(number3));
                        alliesandUserMapper.updateById(a);
                    } else if(number2 < points){
                        Difference =   points-(Turnovervalue+result);
//                    turnovermilitaryvalue
                        number3 =  points-(militaryvalue + result);

                        //新增可用积分记录
                        Pointsrecord pointsrecord = new Pointsrecord();
                        pointsrecord.setCreatetime(tsyUtils.getnowtime());
                        pointsrecord.setCreatappoint(recordofWarMeritConversion.getCreateappoint());
                        pointsrecord.setCreatename(recordofWarMeritConversion.getCreatename());
                        pointsrecord.setPoints(Difference);
                        pointsrecord.setFinnalpoints(number2);
                        pointsrecord.setStatuss("扣减");
                        pointsrecord.setRewordpoeple(a.getName());
                        pointsrecord.setType("周转积分比例调整");
                        pointsrecord.setType2("可用积分");
                        pointsrecord.setCreatenameid(recordofWarMeritConversion.getCreatenameid());
                        pointsrecord.setRewordpoepleid(a.getId());
                        pointsrecord.setCompetitionseason(a.getCompetitionseason());

                        pointsrecord.setRewardorreducedetail(recordofWarMeritConversion.getTitlestime() + "周战功转积分,新比例("+details+")");
                        pointsrecordMapper.insert(pointsrecord);
//                    //更新 可用积分 军工
                        a.setPointes(String.valueOf(number2));
                        a.setMilitaryIndustryall(String.valueOf(number3));
                        alliesandUserMapper.updateById(a);
                    }
                } catch (NumberFormatException e) {
                    // 处理转换异常
                    System.out.println("Invalid number format for one of the strings: " + e.getMessage());
                    log.error("发生异常，方法: someMethod, 参数: [相关信息]", e);
                } catch (Exception e) {
                    // 处理其他可能的异常
                    System.out.println("Unexpected error occurred: " + e.getMessage());
                    log.error("发生异常，方法: someMethod, 参数: [相关信息]", e);
                }
            }

        }
        return ResultData.success(b);
    }

    // 定义一个方法来安全地将字符串转换为整数
    int safeParseInt(String str, String name) {
        if (str == null || str.trim().isEmpty()) {
//            System.out.println("Invalid value for "  +name+ ": " + str);
            return 0;
        }
        try {
            return Integer.parseInt(str.trim());
        } catch (NumberFormatException e) {
//            System.err.println("Failed to parse integer for " +name + ": " + str);
            log.error("发生异常，方法: someMethod, 参数: [相关信息]", e);
            return 0;
        }
    }

}
